import handle from './index';

let reducer = (state = { ...handle.state }, action: { type: string }) => {
  let newState = JSON.parse(JSON.stringify(state))

  // switch (action.type) {
  //   case handle.add1:
  //     handle.actions[handle.add1](newState, action)
  //     break;
  //   case handle.add2:
  //     handle.actions[handle.add2](newState, action)
  //     break;
  //   default:
  //     break
  // }
  for (let key in handle.actions) {
    if (action.type === key) {
      handle.actions[key](newState, action)
      break;
    }
  }

  return newState
}

export default reducer